package test.luin.pers.myapplication;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.List;

public class WeatherServiceJSON {
    public static List<WeatherInfor> getInforFromJSON(InputStream is) {
        List<WeatherInfor> weatherInforList = null;
        try {
            byte[] bytes = new byte[is.available()];
            is.read(bytes);
            String json = new String(bytes, "utf-8");
            Gson gson = new Gson();
            Type type = new TypeToken<List<WeatherInfor>>() {
            }.getType();
            weatherInforList = gson.fromJson(json, type);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return weatherInforList;
    }
}
